//
//  BMSLaunchConfigModel.m
//  WDBMS
//
//  Created by YeJary on 2025/5/12.
//

#import "BMSLaunchConfigModel.h"

@implementation BMSLaunchConfigModel

+ (instancetype)modelWithDictionary:(NSDictionary *)dict {
    BMSLaunchConfigModel *model = [[self alloc] init];
    model.rnAuth = [dict[@"rnAuth"] integerValue];
    model.rnAuthApi = [dict[@"rnAuthApi"] integerValue];
    model.rnNoAuthBtn = [dict[@"rnNoAuthBtn"] integerValue];
    model.att = [dict[@"att"] integerValue];
    model.checkPri = [dict[@"checkPri"] integerValue];
    model.openPri = [dict[@"openPri"] integerValue];
    model.termUrl = dict[@"termUrl"] ?: @"";
    model.privacyUrl = dict[@"privacyUrl"] ?: @"";
    model.bmsUploadIntervalSec = [dict[@"bmsUploadIntervalSec"] integerValue];

    NSMutableArray *tmp = [NSMutableArray array];
    id contentData = dict[@"content"];
    NSLog(@"[BMS] content 类型: %@ -> %@", NSStringFromClass([contentData class]), contentData);

    if ([contentData isKindOfClass:[NSArray class]]) {
        for (NSDictionary *item in (NSArray *)contentData) {
            if ([item isKindOfClass:[NSDictionary class]]) {
                BMSLaunchContentModel *contentModel = [BMSLaunchContentModel modelWithDictionary:item];
                [tmp addObject:contentModel];
            }
        }
    } else if ([contentData isKindOfClass:[NSDictionary class]]) {
        BMSLaunchContentModel *contentModel = [BMSLaunchContentModel modelWithDictionary:(NSDictionary *)contentData];
        [tmp addObject:contentModel];
    } else {
        NSLog(@"[BMS] ⚠️ content 格式异常: %@", contentData);
    }

    model.content = tmp;
    NSLog(@"[BMS] 最终 content.count = %lu", (unsigned long)tmp.count);
    return model;
}

@end

@implementation BMSLaunchContentModel

+ (instancetype)modelWithDictionary:(NSDictionary *)dict {
    BMSLaunchContentModel *model = [[self alloc] init];
    model.sdk_ad_splash_cool = [dict[@"sdk_ad_splash_cool"] boolValue];
    model.sdk_ad_splash_hot = [dict[@"sdk_ad_splash_hot"] boolValue];
    model.sdk_bms_to_ta = [dict[@"sdk_bms_to_ta"] boolValue];
    model.ywIpCitySwitch = [dict[@"ywIpCitySwitch"] integerValue];
    model.ywIpWhiteCitys = dict[@"ywIpWhiteCitys"] ?: @[];
    model.ywIpBlockCitys = dict[@"ywIpBlockCitys"] ?: @[];
    return model;
}

@end
